/**
 * Project Name:scapp-web
 * File Name:AppointmentECController.java
 * Package Name:com.sc.controller
 * Date:2018年7月4日下午5:11:39
 * Copyright (c) 2018, bluemobi All Rights Reserved.
 */

package com.sc.controller;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sc.app.restful.DataResult;
import com.sc.pojo.AppointmentEC;
import com.sc.service.AppointmentECService;

/**
 * Description:   <br/>
 * Date:     2018年7月4日 下午5:11:39 <br/>
 * @author   Qbaba
 * @version
 * @see
 */
@Controller
public class AppointmentECController {

  private final static Logger LOG=LoggerFactory.getLogger(AppointmentECController.class);
    
    
    @Autowired
    private AppointmentECService appointmentecservice;

    @ResponseBody
    @RequestMapping("/selectAppointmentECByYear")
    public List<AppointmentEC> selectAppointmentECByYear() {

        return appointmentecservice.selectAppointmentECByYear();

    }
    
    /**
     * Q -start
     * */
    

    static void setContAndHeader(HttpServletResponse response){
        /*if(aus.verification(username, password)>0){*/
        response.setContentType("text/html;charset=utf-8");          
        //设置响应头允许ajax跨域访问   
        response.setHeader("Access-Control-Allow-Origin", "*");
        //星号表示所有的异域请求都可以接受， 
        response.setHeader("Access-Control-Allow-Methods", "GET,POST");  
    }
    
    
    @ResponseBody
    @RequestMapping(value="inertAppoin")
    public DataResult<Integer> inertAppoin(HttpServletResponse response,String lremark,Timestamp ldate,String name,Integer eid){
    
        AppointmentEC aec=new AppointmentEC();
        aec.setLappiontmenttype(0);
        aec.setLremark(lremark);
        aec.setLdate(ldate);
        aec.setEid(eid);
        aec.setCid(appointmentecservice.selectCidByName(name));
        LOG.info("lremark"+lremark+"ldate"+ldate+"name"+name+"eid"+eid);
        int flag= appointmentecservice.insert(aec);
        return  new DataResult<Integer>(flag);
    
    }
    

    @ResponseBody
    @RequestMapping(value="updateAppOrDate")
    public DataResult<Integer> updateAppOrDate(HttpServletResponse response,String lremark,Timestamp ldate,String name,Integer lappiontmenttype){
        
        LOG.info("lremark"+lremark+"ldate"+ldate+"name"+name+"lappiontmenttype"+lappiontmenttype);
        Map<String,Object> map=new HashMap<String,Object>();
        int inCid=appointmentecservice.selectCidByName(name);
        LOG.info("CID:"+inCid);
        map.put("a_cid", inCid);
        map.put("a_date", ldate);
        map.put("a_lremark", lremark);
        map.put("a_lappiontmenttype", lappiontmenttype);
        int flag= appointmentecservice.updateAppoinmentAndDate(map);
        return  new DataResult<Integer>(flag);
    
    }
}

